package com.srb.core.controller.admin;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.srb.common.result.R;
import com.srb.core.pojo.entity.UserInfo;
import com.srb.core.pojo.query.UserInfoQuery;
import com.srb.core.service.UserInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 用户基本信息 前端控制器
 * </p>
 *
 * @author dapeng
 * @since 2021-08-08
 */
@Api(tags = {"会员管理"})
@Slf4j
//@CrossOrigin
@RestController
@RequestMapping("/admin/core/userInfo")
public class AdminUserInfoController {

    @Autowired
    private UserInfoService userInfoService;

    @ApiOperation(value = "获取会员分页列表")
    @GetMapping(value = "/list/{page}/{limit}")
    public R listPage(
            @ApiParam(value = "当前页码",required = true)
            @PathVariable(value = "page")Long page,
            @ApiParam(value = "每页记录数",required = true)
            @PathVariable(value = "limit")Long limit,
            @ApiParam(value = "查询对象",required = false)
            UserInfoQuery userInfoQuery){
        Page<UserInfo> pageParam = new Page<UserInfo>(page, limit);
        IPage<UserInfo> pageModel = userInfoService.listPage(pageParam,userInfoQuery);
        return R.ok().data("pageModel",pageModel);
    }

    @ApiOperation(value = "锁定和解锁")
    @PutMapping(value = {"/lock/{id}/{status}"})
    public R lock(
            @ApiParam(value = "用户ID",required = true)
            @PathVariable(value = "id")Long id,
            @ApiParam(value = "锁定状态(0：锁定 1：正常)",required = true)
            @PathVariable(value = "status")Integer status){
        userInfoService.lock(id,status);
        return R.ok().message(status == 1 ? "解锁成功":"锁定成功");
    }
}

